// RouteNetClient.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "RouteNetClient.h"
#include "RouteNetClientDlg.h"

#include "xdl\route_net_c_api.h"
#include "xdl\c_api\route_net_param.cpp"
#include "xdl\c_api\route_net_c_api.cpp"
#include "route_net_c_serve.h"

#include "xdl\ui_route_net_c_api.h"
#include "xdl\c_api\ui_route_net_param.cpp"
#include "xdl\c_api\ui_route_net_c_api.cpp"
#include "ui_route_net_c_serve.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

ITransmit* gpTransmit = NULL;
#ifndef NOT_USE_PROACTOR
McTimeoutHandler* gpTimeoutHandler = NULL;

#define ACT_INIT 1
#define ACT_FINI 2
void act_init()
{
	gpTransmit = new McProactorTransmit(".\\ui_route_net_c_", new McTransmitEvent, true);
}
void act_fini()
{
	delete gpTransmit;
}
#endif

/////////////////////////////////////////////////////////////////////////////
// CRouteNetClientApp

BEGIN_MESSAGE_MAP(CRouteNetClientApp, CWinApp)
	//{{AFX_MSG_MAP(CRouteNetClientApp)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG
	ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CRouteNetClientApp construction

CRouteNetClientApp::CRouteNetClientApp()
{
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CRouteNetClientApp object

CRouteNetClientApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CRouteNetClientApp initialization

BOOL CRouteNetClientApp::InitInstance()
{
	AfxEnableControlContainer();

	// Standard initialization
	// If you are not using these features and wish to reduce the size
	//  of your final executable, you should remove from the following
	//  the specific initialization routines you do not need.

#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif

	ACEBaseApp::init();  
#ifndef NOT_USE_PROACTOR
	ACEBaseApp::reactor(ACE_Reactor::instance());
#endif
	ACEBaseApp::startEventLoop();
#ifndef NOT_USE_PROACTOR
	gpTimeoutHandler = new McTimeoutHandler;
	gpTimeoutHandler->set_action_fn(ACT_INIT, act_init);
	gpTimeoutHandler->set_action_fn(ACT_FINI, act_fini);
	
	gpTimeoutHandler->exec_action(ACT_INIT);
#else
	gpTransmit = new McReactorTransmit(".\\ui_route_net_c_", new McTransmitEvent_Simple, true);
#endif

	gpServe_route_net_c_impl = new McServe_route_net_c_Impl();
	gpServe_route_net_c = new McServe_route_net_c(gpServe_route_net_c_impl);
	gpTransmit->add_dispunit(new McDisp_route_net_c(gpServe_route_net_c, true));

	gpServe_ui_route_net_c_impl = new McServe_ui_route_net_c_Impl();
	gpServe_ui_route_net_c = new McServe_ui_route_net_c(gpServe_ui_route_net_c_impl);
	gpTransmit->add_dispunit(new McDisp_ui_route_net_c(gpServe_ui_route_net_c, true));
	
	CRouteNetClientDlg dlg;
	m_pMainWnd = &dlg;
	dlg.DoModal();

	// Since the dialog has been closed, return FALSE so that we exit the
	// application, rather than start the application's message pump.
	return FALSE;
}

int CRouteNetClientApp::ExitInstance() 
{
	// TODO: Add your specialized code here and/or call the base class
#ifndef NOT_USE_PROACTOR
	gpTimeoutHandler->exec_action(ACT_FINI);
	delete gpTimeoutHandler;
#else
	delete gpTransmit;
#endif
	ACEBaseApp::endEventLoop();
	ACEBaseApp::fini();
	
	return CWinApp::ExitInstance();
}

